// pages/mine/mine.js
Page({
  data: {
    userInfo: {
      avatarUrl: '',
      username: ''
    }
  },

  onLoad: function() {
    this.updateUserInfo();
    
  },

  onShow: function() {
    this.updateUserInfo();
    const app = getApp();
    const token = app.globalData.token;
    console.log(`this is mine page ${token} token is over`);
  },

  updateUserInfo: function() {
    // 检查用户是否已登录
    const storedUserInfo = wx.getStorageSync('base_candidate_info') || {};
    if(storedUserInfo.name){
      this.setData({
        userInfo: {
          avatarUrl: '/icon/Crystal.png' || '',
          username: storedUserInfo.name || ''
        }
      });
    }else{
      this.setData({
        userInfo: {
          avatarUrl:  '',
          username:  ''
        }
      });
    }
    
  },

  login: function() {
    wx.navigateTo({
      url: '/pages/login/login',
    });
  },

  logout: function() {
    // 处理退出登录逻辑
    wx.clearStorageSync();
    this.setData({
      userInfo: {
        avatarUrl: '',
        username: ''
      }
    });
    wx.showToast({
      title: '已退出登录',
      icon: 'success'
    });
  },
  
  goToSettings: function() {
    // 跳转到设置页面
    wx.navigateTo({
      url: '/pages/settings/settings'
    });
  },

  viewProfile: function() {
    // 跳转到个人信息展示页面
    wx.navigateTo({
      url: '/pages/profile/profile'
    });
  },

  fileManager:function () {
    wx.navigateTo({
      url: '/pages/fileManager/fileManager',
    })
  }
});
